<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:content identifier="information" ignore="true" />
<atleap:messages />

<atleap:form action="core/statistics/total/daily" method="GET" validateOnSubmit="false">
    <html:text property="year" styleClass="textYear" />
    <html:select property="month">
        <atleap:iterator begin="1" end="12" var="month" >
            <html:option value="${month}">
                <atleap:formatDate value="${month}/01/2000" pattern="MMMMM" />
            </html:option>
        </atleap:iterator>
    </html:select>
    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.refresh" /></atleap:submit>
</atleap:form>

<c:set var="maxTotal" value="${maxTotal}" />
<c:set var="maxUnique" value="${maxUnique}" />
<c:set var="maxBarWidth" value="100" />
<c:set var="barHeight" value="10" />

<h3><atleap:formatDate value="${requestScope.date}" pattern="MMMMM yyyy" /></h3>

<table border="0" cellpadding="0" cellspacing="0" class="totalsChart">
    <tr>
        <th width="20">
            <atleap:message key="core.statistics.totals.day" />
        </th>
        <th></th>
        <th width="20">
            <atleap:message key="core.statistics.totals.number" />
        </th>
    </tr>
    <atleap:iterator items="${days}" var="dayDescr">
        <c:set var="day" value="${dayDescr[0]}" />
        <c:set var="total" value="${dayDescr[1]}" />
        <c:set var="unique" value="${dayDescr[2]}" />
        <c:set var="totalFraction" value="${total / maxTotal}" />
        <c:set var="uniqueFraction" value="${unique / maxUnique}" />
        <fmt:formatNumber value="${totalFraction * maxBarWidth}" maxFractionDigits="0" groupingUsed="false" var="totalBarWidth" />
        <fmt:formatNumber value="${uniqueFraction * maxBarWidth}" maxFractionDigits="0" groupingUsed="false" var="uniqueBarWidth" />
        <tr>
            <td align="center">
                ${day}
            </td>
            <td>
                <table border="0" cellpadding="0" cellspacing="0" class="twoRowTable">
                    <tr>
                        <td class="twoRowTableCell">
                            <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color1_pixel.gif" />" width="${totalBarWidth}%" height="${barHeight}" />
                        </td>
                    </tr>
                    <tr>
                        <td class="twoRowTableCell">
                            <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color2_pixel.gif" />" width="${uniqueBarWidth}%" height="${barHeight}" />
                        </td>
                    </tr>
                </table>
            </td>
            <td>
                <table border="0" cellpadding="0" cellspacing="0" class="twoRowTable">
                    <tr>
                        <td align="center" class="twoRowTableCell">
                            ${total}
                        </td>
                    </tr>
                    <tr>
                        <td align="center" class="twoRowTableCell">
                            ${unique}
                        </td>
                    </tr>
                </table>
            </td>
         </tr>
    </atleap:iterator>
    <bean:size id="numberOfDays" collection="${days}" />
    <c:if test="${numberOfDays == 0}">
        <tr>
            <td class="tfoot" colspan="3" align="center">
                <em><atleap:message key="core.commons.nothingToShow"/></em>
            </td>
        </tr>
    </c:if>
</table>

<h3><atleap:message key="core.statistics.legend" /></h3>
<table border="0" cellpadding="0" cellspacing="0" class="totalsChartLegend">
    <tr>
        <th>
            <atleap:message key="core.statistics.totals.total" />
        </th>
        <td>
            <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color1_pixel.gif" />" width="${maxBarWidth}" height="${barHeight}" />
        </td>
    </tr>
    <tr>
        <th>
            <atleap:message key="core.statistics.totals.unique" />
        </th>
        <td>
            <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color2_pixel.gif" />" width="${maxBarWidth}" height="${barHeight}" />
        </td>
    </tr>
</table>

<atleap:form action="core/statistics/showPanel" method="GET" validateOnSubmit="false">
    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.back" /></atleap:submit>
</atleap:form>
